package com.define.commons.dao.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.gitee.fastmybatis.core.annotation.LogicDelete;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Model基类
 * @Author xiewenlong
 * @Date 2018/11/6 10:14
 */
@Data
@ApiModel
@MappedSuperclass
public class BaseModel implements Serializable {

    /**
     *  主键
     *  自增
     */
    @Id
    @ApiModelProperty(value = "主键", readOnly = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     *  插入时间
     *  fastmybatis在插入数据的时候会自动填充该字段
     */
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "插入时间", readOnly = true)
    @Column(name = "insert_time", updatable = false, columnDefinition = "DATETIME COMMENT '添加时间'")
    private Date insertTime;

    /**
     *  修改时间
     *  fastmybatis在修改该条数据的时候会自动填充该字段
     */
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "修改时间", readOnly = true)
    @Column(name = "update_time", columnDefinition = "DATETIME COMMENT '修改时间'")
    private Date updateTime;

    /**
     *  针对fastmybatis框架有效
     *  逻辑删除字段
     *  0 表示未删除
     *  1 表示已删除
     *  使用fastmybatis框架中的删除方法后再使用fastmybatis的查询方法就查询不到了
     */
    @LogicDelete
    @ApiModelProperty(value = "是否已删除 0:未删除 1:已删除", readOnly = true)
    @Column(name = "is_del", columnDefinition = "INT(1) DEFAULT 0 COMMENT '是否已删除'")
    private int isDel;

}
